from typing import List


class Solution:
    def isSelfCrossing(self, x: List[int]) -> bool:
        for i in range(len(x)):
            if i >= 3:
                if x[i] >= x[i - 2] and x[i - 1] <= x[i - 3]:
                    return True
            if i >= 4:
                if x[i] >= x[i - 2] - x[i - 4] and x[i - 1] == x[i - 3]:
                    return True
            if i >= 5:
                if x[i] >= x[i - 2] - x[i - 4] and x[i - 1] >= x[i - 3] - x[i - 5] and x[i - 2] >= x[i - 4] and x[
                    i - 3] >= x[i - 1]:
                    return True
        return False


if __name__ == "__main__":
    print(Solution().isSelfCrossing([2, 1, 1, 2]))  # True
    print(Solution().isSelfCrossing([1, 2, 3, 4]))  # False
    print(Solution().isSelfCrossing([1, 1, 1, 1]))  # True
    print(Solution().isSelfCrossing([1, 1, 2, 1, 1]))  # True
    print(Solution().isSelfCrossing([1, 1, 2, 2, 1, 1]))  # True
